//
//  XJThirdViewController.m
//  BiologyLibrary
//
//  Created by 朱进 on 16/7/10.
//  Copyright © 2016年 youxh. All rights reserved.
//

#import "XJThirdViewController.h"
#import "XJSecondStepViewController.h"

@implementation XJThirdViewController

static const NSString * KEY_STEP  = @"step3";


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _currentStep = self.NewRecordArray.firstObject.savedStepCount + 1;
    _keyStepStr = [NSString stringWithFormat:@"step%zd", _currentStep];
    NSLog(@"setp%zd record === %@", _currentStep, self.NewRecordArray.firstObject.getDetailDict);
    
    [self setNaviBarTitle:self.NewRecordArray.firstObject.name];
    _maintableview=[[UITableView alloc]initWithFrame:CGRectMake(10, 64, fWidth_Current-20, fHeight_Current-64-50)];
    _maintableview.backgroundColor = [UIColor clearColor];
    _maintableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _maintableview.dataSource = self;
    _maintableview.delegate = self;
    _maintableview.showsVerticalScrollIndicator=NO;
    [self.view addSubview:_maintableview];
    
    UIImageView*buttomview=[[UIImageView alloc]initWithFrame:CGRectMake(0, fHeight_Current-50, fWidth_Current, 50)];
    buttomview.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
    [self.view addSubview:buttomview];
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 50)];
    label.backgroundColor=[UIColor clearColor];
    label.textAlignment=1;
    label.font=[UIFont systemFontOfSize:14];
    label.textColor=[UIColor lightGrayColor];
    label.text= [NSString stringWithFormat:@"当下是第%zd/%zd步", self.NewRecordArray.firstObject.savedStepCount + 1, self.NewRecordArray.firstObject.allStepCount];
    [buttomview addSubview:label];
    speedArr=[[NSMutableArray alloc]init];
    numberArr=[[NSMutableArray alloc]init];
    wenduArr=[[NSMutableArray alloc]init];
    timearr=[[NSMutableArray alloc]init];
    
    [numberArr addObjectsFromArray:[APPUserDict objectForKey:@"lixingarr"]];
    [wenduArr addObjectsFromArray:[APPUserDict objectForKey:@"wenduarr"]];
    [timearr addObjectsFromArray:[APPUserDict objectForKey:@"timearr"]];
    [speedArr addObjectsFromArray:[APPUserDict objectForKey:@"speedarr"]];
    
    pickerview = [[ZJPickerview alloc] initWithTitle:@"速度选择" KeyName:nil];
    pickerview.zjDelegate = self;
    pickerview2 = [[ZJPickerview alloc] initWithTitle:@"温度选择" KeyName:nil];
    pickerview2.zjDelegate = self;
    pickerview3 = [[ZJPickerview alloc] initWithTitle:@"序号选择" KeyName:nil];
    pickerview3.zjDelegate = self;
    pickerview4 = [[ZJPickerview alloc] initWithTitle:@"时长选择" KeyName:nil];
    pickerview4.zjDelegate = self;
    _iSelectedIndex=0;
    _iSelectedIndex2=0;
    _iSelectedIndex3=0;
    _iSelectedIndex4=0;
    
}
#pragma mark - UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 4;
        
    }else if(section==1 ||section==2) {
        return 2;
        
    }else{
        return 1;
        
    }
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;//返回标题数组中元素的个数来确定分区的个数
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==2) {
        return 50;
        
    }else{
        return 60;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 18)];
    headview.backgroundColor=[UIColor clearColor];
    return headview;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *strIdentifier = [NSString stringWithFormat:@"strIdentifier%zd%zd",indexPath.section,indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIdentifier];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:strIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
        
        UILabel*firstlabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 60, 60)];
        firstlabel.backgroundColor=[UIColor clearColor];
        firstlabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
        [cell addSubview:firstlabel];
        switch (indexPath.section) {
            case 0:
                if (indexPath.row==0) {
                    NSString*titlestr=@"3.1、离心条件。";
                    
                    UILabel *titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, fWidth_Current-40, 60)];
                    titlelab.textColor=[UIColor whiteColor];
                    titlelab.backgroundColor=[UIColor clearColor];
                    titlelab.text=titlestr;
                    titlelab.numberOfLines=0;
                    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,60, fWidth_Current-20, 0.5)];
                    lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
                    [cell addSubview:titlelab];
                    [cell addSubview:lineview];
                    
                }else if (indexPath.row==1){
                    firstlabel.text=@"速度：";
                    speedLabel=[[UILabel alloc]initWithFrame:CGRectMake(10+55, 0, fWidth_Current-40-55, 60)];
                    speedLabel.backgroundColor=[UIColor clearColor];
                    speedLabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    speedLabel.text=@"45m/s";

                    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,60, fWidth_Current-20, 0.5)];
                    lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
                    [cell addSubview:speedLabel];
                    [cell addSubview:lineview];
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 18, 50, 25)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn1.layer.cornerRadius=10;
                    [btn1 setTitle:@"选择" forState:UIControlStateNormal];
                    [btn1 addTarget:self action:@selector(selectspeed) forControlEvents:UIControlEventTouchUpInside];
                    btn1.titleLabel.font=[UIFont systemFontOfSize:11];
                    btn1.clipsToBounds=YES;
                    [cell addSubview:btn1];
                    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] &&
                        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] count] > 0 &&
                        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:0] objectForKey:KEY_RECORD_ANSWER]) {
                        
                        speedLabel.text = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:0] objectForKey:KEY_RECORD_ANSWER];
                    }
                    
                    if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                        btn1.hidden = YES;
                    }else{
                        btn1.hidden = NO;
                    }
                }else if (indexPath.row==2){
                    firstlabel.text=@"时长：";
                    dateLabel=[[UILabel alloc]initWithFrame:CGRectMake(10+55, 0, fWidth_Current-40-55, 60)];
                    dateLabel.textColor=[UIColor whiteColor];
                    dateLabel.backgroundColor=[UIColor clearColor];
                    dateLabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    dateLabel.text =@"1小时";

                    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,60, fWidth_Current-20, 0.5)];
                    lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
                    [cell addSubview:dateLabel];
                    [cell addSubview:lineview];
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 18, 50, 25)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn1.layer.cornerRadius=10;
                    [btn1 setTitle:@"选择" forState:UIControlStateNormal];
                    [btn1 addTarget:self action:@selector(selecttime) forControlEvents:UIControlEventTouchUpInside];
                    btn1.titleLabel.font=[UIFont systemFontOfSize:11];
                    btn1.clipsToBounds=YES;
                    [cell addSubview:btn1];
                    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] &&
                        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] count] > 1 &&
                        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:1] objectForKey:KEY_RECORD_ANSWER]) {
                        
                        dateLabel.text = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:1] objectForKey:KEY_RECORD_ANSWER];
                    }
                    
                    if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                        btn1.hidden = YES;
                    }else{
                        btn1.hidden = NO;
                    }
                }else if (indexPath.row==3){
                    firstlabel.text=@"温度：";
                    
                    wenduLabel=[[UILabel alloc]initWithFrame:CGRectMake(10+55,0, fWidth_Current-40-55, 60)];
                    wenduLabel.textColor=[UIColor whiteColor];
                    wenduLabel.backgroundColor=[UIColor clearColor];
                    wenduLabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    wenduLabel.text=@"10℃";

                    [cell addSubview:wenduLabel];
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 18, 50, 25)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn1.layer.cornerRadius=10;
                    [btn1 setTitle:@"选择" forState:UIControlStateNormal];
                    [btn1 addTarget:self action:@selector(selectwendu) forControlEvents:UIControlEventTouchUpInside];
                    btn1.titleLabel.font=[UIFont systemFontOfSize:11];
                    btn1.clipsToBounds=YES;
                    [cell addSubview:btn1];
                    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] &&
                        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] count] > 2 &&
                        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:2] objectForKey:KEY_RECORD_ANSWER]) {
                        
                        wenduLabel.text = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:2] objectForKey:KEY_RECORD_ANSWER];
                    }
                    
                    if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                        btn1.hidden = YES;
                    }else{
                        btn1.hidden = NO;
                    }
                }
                break;
            case 1:{
                if (indexPath.row==0) {
                    NSString*titlestr=@"3.2、离心机序号。";
                    
                    UILabel *titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, fWidth_Current-40, 60)];
                    titlelab.textColor=[UIColor whiteColor];
                    titlelab.backgroundColor=[UIColor clearColor];
                    titlelab.text=titlestr;
                    titlelab.numberOfLines=0;
                    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,60, fWidth_Current-20, 0.5)];
                    lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
                    [cell addSubview:titlelab];
                    [cell addSubview:lineview];
                }else if (indexPath.row==1){
                    firstlabel.text=@"序号：";
                    
                    numberLabel=[[UILabel alloc]initWithFrame:CGRectMake(10+55, 0, fWidth_Current-40-55, 60)];
                    numberLabel.textColor=[UIColor whiteColor];
                    numberLabel.backgroundColor=[UIColor clearColor];
                    numberLabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    numberLabel.text=@"LXJ001";

                    [cell addSubview:numberLabel];
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 18, 50, 25)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn1.layer.cornerRadius=10;
                    [btn1 setTitle:@"选择" forState:UIControlStateNormal];
                    [btn1 addTarget:self action:@selector(selectnumber) forControlEvents:UIControlEventTouchUpInside];
                    btn1.titleLabel.font=[UIFont systemFontOfSize:11];
                    btn1.clipsToBounds=YES;
                    [cell addSubview:btn1];
                    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] &&
                        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] count] > 3 &&
                        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:3] objectForKey:KEY_RECORD_ANSWER]) {
                        
                        numberLabel.text = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:3] objectForKey:KEY_RECORD_ANSWER];
                    }
                    
                    if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                        btn1.hidden = YES;
                    }else{
                        btn1.hidden = NO;
                    }
                }
            }
                break;
            case 2:{
                if (indexPath.row==0) {
                    NSString*titlestr=@"3.3、记录离心时间。";
                    
                    UILabel *titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, fWidth_Current-40, 60)];
                    titlelab.textColor=[UIColor whiteColor];
                    titlelab.backgroundColor=[UIColor clearColor];
                    titlelab.text=titlestr;
                    titlelab.numberOfLines=0;
                    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,60, fWidth_Current-20, 0.5)];
                    lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
                    [cell addSubview:titlelab];
                    [cell addSubview:lineview];
                }else if (indexPath.row==1){
                    firstlabel.text=@"时间：";
                    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] &&
                        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] count] > 4 &&
                        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:4] objectForKey:KEY_RECORD_ANSWER]) {
                        
                        savetime = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:_keyStepStr] objectAtIndex:4] objectForKey:KEY_RECORD_ANSWER];
                    }
                    
                    datelabel=[[UILabel alloc]initWithFrame:CGRectMake(10+55, 0, fWidth_Current-40-55, 60)];
                    datelabel.textColor=[UIColor whiteColor];
                    datelabel.backgroundColor=[UIColor clearColor];
                    datelabel.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    [cell addSubview:datelabel];
                    datelabel.text=savetime;
                    
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 18, 50, 25)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn1.layer.cornerRadius=10;
                    [btn1 setTitle:@"刷新" forState:UIControlStateNormal];
                    [btn1 addTarget:self action:@selector(reloadtime) forControlEvents:UIControlEventTouchUpInside];
                    btn1.titleLabel.font=[UIFont systemFontOfSize:11];
                    btn1.clipsToBounds=YES;
                    [cell addSubview:btn1];
                    if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                        btn1.hidden = YES;
                    }else{
                        btn1.hidden = NO;
                    }
                }
            }
                break;
                
            case 3:{
                cell.backgroundColor=[UIColor clearColor];
                
                if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                    
                    UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
                    btn2.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn2.layer.cornerRadius=5;
                    [btn2 setTitle:@"下一步" forState:UIControlStateNormal];
                    btn2.clipsToBounds=YES;
                    [btn2 addTarget:self action:@selector(nextStepClick) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:btn2];
                }else{
                    
                    UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, (fWidth_Current-30)/2, 50)];
                    btn1.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
                    btn1.layer.cornerRadius=5;
                    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
                    btn1.clipsToBounds=YES;
                    [btn1 addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:btn1];
                    UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake((fWidth_Current-30)/2+10, 0, (fWidth_Current-30)/2, 50)];
                    btn2.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
                    btn2.layer.cornerRadius=5;
                    [btn2 setTitle:@"保存" forState:UIControlStateNormal];
                    btn2.clipsToBounds=YES;
                    [btn2 addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:btn2];
                }
            }
                break;
                
            default:
                break;
        }
    }
    return cell;
}
-(void)selectspeed{
    if (pickerview.isShowed==NO) {
        [pickerview showInView:self.view withArray:speedArr selectedIndex:_iSelectedIndex];
    }
}
-(void)selecttime{
    if (pickerview4.isShowed==NO) {
        [pickerview4 showInView:self.view withArray:timearr selectedIndex:_iSelectedIndex4];
    }
}
- (NSString *)dateToString:(NSDate *)date {
    
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT+0800"];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM-dd hh:mm"];
    
    [formatter setTimeZone:timeZone];
    
    NSString * timeString = [formatter stringFromDate:date];
    
    return timeString;
}

-(void)selectwendu{
    if (pickerview2.isShowed==NO) {
        [pickerview2 showInView:self.view withArray:wenduArr selectedIndex:_iSelectedIndex2];
    }
}
-(void)selectnumber{
    if (pickerview3.isShowed==NO) {
        [pickerview3 showInView:self.view withArray:numberArr selectedIndex:_iSelectedIndex3];
    }
}
-(void)saveClick{
    if(speedLabel.text == nil || [speedLabel.text isEqualToString:@""]){
        [self.view makeToast:@"请选择速度！"];
        return;
    }
    
    if(dateLabel.text == nil || [dateLabel.text isEqualToString:@""]){
        [self.view makeToast:@"请选择时长！"];
        return;
    }
    if(wenduLabel.text == nil || [wenduLabel.text isEqualToString:@""]){
        [self.view makeToast:@"请选择温度！"];
        return;
    }
    if(numberLabel.text == nil || [numberLabel.text isEqualToString:@""]){
        [self.view makeToast:@"请选择序号！"];
        return;
    }
    if(datelabel.text == nil || [datelabel.text isEqualToString:@""]){
        [self.view makeToast:@"请纪录离心时间！"];
        return;
    }
    NSString*step3date = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:@"step2"] objectAtIndex:0] objectForKey:KEY_RECORD_ANSWER];
    NSString*step4date = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:KEY_STEP] objectAtIndex:4] objectForKey:KEY_RECORD_ANSWER];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd hh:mm"];
    NSDate *date1=[formatter dateFromString:step3date];
    NSDate *date3=[formatter dateFromString:step4date];
    
    
    
    NSTimeInterval secondsInterval= [date3 timeIntervalSinceDate:date1];
    
    if (secondsInterval<0) {
        [self.view makeToast:@"抱歉，离心时间不能小于抽血时间"];
        return;
    }

    [self creatDetailDict];
    XJSecondStepViewController *fourthVC = [[XJSecondStepViewController alloc] init];
    fourthVC.NewRecordArray = self.NewRecordArray;
    [self.navigationController pushViewController:fourthVC animated:YES];
}
#pragma mark - ZJPickerviewDelegate
-(void)ZJPickerview:(ZJPickerview *)zjPickerview didFineshesAtIndex:(int)index{
    if (zjPickerview==pickerview) {
        _iSelectedIndex=index;
        speedLabel.text=[NSString stringWithFormat:@"%@",[speedArr objectAtIndex:index]];
        
    }else if(zjPickerview==pickerview2){
        _iSelectedIndex2=index;
        wenduLabel.text=[NSString stringWithFormat:@"%@",[wenduArr objectAtIndex:index]];
        
        
    }else if(zjPickerview==pickerview4){
        _iSelectedIndex4=index;
        dateLabel.text=[NSString stringWithFormat:@"%@",[timearr objectAtIndex:index]];
        
        
    }else{
        _iSelectedIndex3=index;
        numberLabel.text=[NSString stringWithFormat:@"%@",[numberArr objectAtIndex:index]];
        
    }
    //    [timebtn setTitle:[timearr objectAtIndex:_iSelectedIndex] forState:UIControlStateNormal];
}

-(void)reloadtime{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    savetime=dateString;
    datelabel.text=savetime;
}

-(void)creatDetailDict{
    
    NSDictionary *question1Dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"速度", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   speedLabel.text, KEY_RECORD_ANSWER, nil];
    NSDictionary *question2Dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"时间", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   dateLabel.text, KEY_RECORD_ANSWER, nil];
    NSDictionary *question3Dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"温度", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   wenduLabel.text, KEY_RECORD_ANSWER, nil];
    NSDictionary *question4Dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"序号", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   numberLabel.text, KEY_RECORD_ANSWER, nil];
    NSDictionary *question5Dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"时间", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   savetime, KEY_RECORD_ANSWER, nil];
    
    NSArray *qustionArr = [NSArray arrayWithObjects:question1Dict, question2Dict,question3Dict,question4Dict,question5Dict, nil];
    for (Record *oneRecord in self.NewRecordArray) {
        NSMutableDictionary *tempDict = [oneRecord getDetailDict];
        [tempDict setObject:qustionArr forKey:_keyStepStr];
        [oneRecord setDetailDict:tempDict];
        oneRecord.recordDetail = [tempDict JSONString];
        oneRecord.savedStepCount = _currentStep;
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [oneRecord update];
        });
        
    }
   
}
-(void)cancelclick{
    UIViewController*miloViewControl=(UIViewController *)[[self.navigationController viewControllers]objectAtIndex:1];
    [self.navigationController popToViewController:miloViewControl animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)nextStepClick{
    
    self.NewRecordArray.firstObject.savedStepCount = _currentStep;
    
    XJSecondStepViewController *fourthVC = [[XJSecondStepViewController alloc] init];
    fourthVC.NewRecordArray = self.NewRecordArray;
    fourthVC.fromtype = @"search";
    [self.navigationController pushViewController:fourthVC animated:YES];
}

@end
